#include "doubleclicked.h"
#include "ui_doubleclicked.h"
#include <QDebug>
#define LOG qDebug() << "[" << __FILE__ << ":" << __LINE__ << ":" << __func__ << "]"

doubleClicked::doubleClicked(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::doubleClicked)
{
    ui->setupUi(this);
    this->setWindowFlags(this->windowFlags() &~ Qt::WindowMinMaxButtonsHint | Qt::WindowStaysOnTopHint);
    this->setWindowTitle("设置");
    this->setFixedSize(705, 267);

    /* 限制文本框输入限制 */
    /* 数量 */
    QRegExp countrx("^([1-9][0-9]*)(\\.[0-9]*)$|^[1-9][0-9]*$");
    QRegExpValidator *countReg = new QRegExpValidator(countrx, this);
    ui->countLineEdit->setValidator(countReg);

    /* 备注 */
    connect(ui->commentTextEdit, &QTextEdit::textChanged, this, [=](){
        if(ui->commentTextEdit->toPlainText().size() > 500) {
            /* 获取当前光标 */
            QTextCursor cursor = ui->commentTextEdit->textCursor();
            /* 获取当前光标位置 */
            int position = ui->commentTextEdit->textCursor().position();
            /* 限制文本框值 */
            ui->commentTextEdit->setPlainText(ui->commentTextEdit->toPlainText().mid(0, 500));
            /* 设置文本框光标位置 */
            cursor.setPosition(500, QTextCursor::MoveAnchor);
            ui->commentTextEdit->setTextCursor(cursor);
        }
    });

    /* 样本点设置 */
    connect(ui->sampleComboBox, SIGNAL(activated(const int)), this, SLOT(sampleSetting(const int)));

    /* 靶基因点设置 */
    connect(ui->targetComboBox, SIGNAL(activated(const int)), this, SLOT(targetSetting(const int)));
}

doubleClicked::~doubleClicked()
{
    delete ui;
}


void doubleClicked::sampleSetting(const int data){
    emit doubleClicked::sampleData(data);
    LOG << "view选择样本点";
}

void doubleClicked::targetSetting(const int data){
    emit doubleClicked::targetData(data);
    LOG << "view选择靶基因点";
}
